package b2.widget.rank
{
	import b2.config.*;
	import b2.net.*;
	import b2.player.RankingInfo;
	import b2.player.RankingPackage;
	import b2.util.*;
	import b2.widget.tab.*;
	
	import flash.filters.*;
	import flash.text.*;
	
	public class RankingDialog extends TabController
	{
		private static var instance:RankingDialog;
		
		public function RankingDialog()
		{
			var RankingDialogBgr:Class = ResourceHelper.getInstance().getClassByName("RankingDialogBgr");
			var TabTitleBackground:Class = ResourceHelper.getInstance().getClassByName("ButtonBgr6");
			var HighlightTitleBgr:Class = ResourceHelper.getInstance().getClassByName("ButtonBgr3");
			var CloseButton:Class = ResourceHelper.getInstance().getClassByName("CloseButton");
			super(RankingDialogBgr, CloseButton);
			//标题
			var titleText:TextField = new TextField();
			titleText.selectable = false;
        	titleText.autoSize = TextFieldAutoSize.CENTER;
        	var titleFomat:TextFormat = new TextFormat("微软雅黑", 16, 0xFFFFFF);
        	titleFomat.letterSpacing = 10;
			titleText.defaultTextFormat = titleFomat;
			titleText.filters = [new GlowFilter(0x000000, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			titleText.text = "荣誉堂";
			titleText.x = (this.width - titleText.width) / 2;
			titleText.y = 13;
			addChild(titleText);
			var tab:RankingTab = new RankingTab(0);
			tab.setPageSelectorPos(150, 310);
			this.addTab(TabTitleBackground, tab.tabName, tab, HighlightTitleBgr);
			tab = new RankingTab(1);
			tab.setPageSelectorPos(150, 310);
			this.addTab(TabTitleBackground, tab.tabName, tab, HighlightTitleBgr);
			tab = new RankingTab(2);
			tab.setPageSelectorPos(150, 310);
			this.addTab(TabTitleBackground, tab.tabName, tab, HighlightTitleBgr);
			this.setTabTitlePos(25, 52); 
			this.setTabPagePos(16, 104);
			this.setCloseButtonPos(this.width - 44, 14);
		}
		
		public static function getInstance():RankingDialog
		{
			if (!instance)
				instance = new RankingDialog();
			return instance;
		}
		
		public function refresh(rankingPackage:RankingPackage):void
		{
			for (var i:int = 0; i < rankingPackage.rankingList.length; i++)
			{
				var tab:Tab = tabs[i];
				tab.removeAll();
				var rankings:Array = rankingPackage.rankingList[i];
				for (var j:int = 0; j < rankings.length; j++)
				{
					var rankingInfo:RankingInfo = rankings[j];
					var rankingItem:RankingItem = new RankingItem(j + 1, rankingInfo);
					tab.addItem(rankingItem, rankingItem.width, rankingItem.height);
				}
			} 
			
		}
		
		public function close():void
		{
			if (this.parent != null)
				this.parent.removeChild(this);
		}
		
	}
}